package actions;


import flixel.FlxSprite;
import flixel.tweens.FlxTween;
import flixel.tweens.FlxEase;


/****
 * Clase base para las acciones y contenedores
 * Posee métodos para mover de forma interpolada
 */
class BasicAction extends FlxSprite{
	public var parentContainer: BasicContainer;
	public var positionInsideParent: Int; // necesitamos esto???
	public var actionType: String;

	public function new(x: Float = 0, y: Float = 0){
		super(x, y);
		parentContainer = null;
		actionType = "";
	}

	public function tweenedMove(_x: Float, _y: Float){
		// si ya está en posición o está haciendo tweening, no hace nada
		if ((x == _x && y == _y) || _isTweeningPos ) return;
		else{
			var options:TweenOptions = { type: FlxTween.ONESHOT, ease: TWEENED_MOVE_EASING, complete: onTweenedMoveEnd}
			
			_isTweeningPos = true;
			_posTween = FlxTween.tween(this, {"x": _x, "y": _y}, TWEENED_MOVE_DURATION, options);
		}
	}



	private function onTweenedMoveEnd(tween: FlxTween): Void{
		_isTweeningPos = false;
	}



	private var _posTween: FlxTween;

	private var _isTweeningPos: Bool = false;
	private static inline var TWEENED_MOVE_DURATION: Float = 0.1;
	private static var TWEENED_MOVE_EASING: EaseFunction = FlxEase.quadIn;
}